package com.youmu.shop.product.controller;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.exception.ParamException;
import com.result.Result;
import com.result.ResultUtils;
import com.youmu.shop.product.service.ProductService;
import com.youmu.shop.product.service.ProductSpecificationService;
import com.youmu.shop.product.vo.BannerVo;
import com.youmu.shop.product.vo.ProductCategoryVO;
import com.youmu.shop.product.vo.ProductSpecificationVO;
import com.youmu.shop.product.vo.ProductVO;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;


@RestController
@RequestMapping(value = "/product/remote/")
public class ProductController {

	@Resource
    private ProductService productService;
	
	@Resource
    private ProductSpecificationService productSpecificationService;
	
	@ApiOperation(value = "首页 Banner")
    @RequestMapping(value = "getBanners",method=RequestMethod.GET)
    public Result<BannerVo> getBanners() {
        List<BannerVo>  bannerVos = productService.getBanners();
        return ResultUtils.createDefResult(bannerVos);
    }
    
    @ApiOperation(value = "查询商品分类(首页)")
    @ApiImplicitParams({
		@ApiImplicitParam(name = "productName", value = "商品名称", required = false, dataType = "String", paramType = "query") 
    })
	@RequestMapping(value = "findProductCategory",method=RequestMethod.GET)
	public Result<ProductCategoryVO> findProductCategory(String productName) {
    	List<ProductCategoryVO>  productCategoryVOs = productService.findProductCategory(productName);
    	return ResultUtils.createDefResult(productCategoryVOs);
	}
    
    @ApiOperation(value = "查询商品分类(首页)")
    @ApiImplicitParams({
		@ApiImplicitParam(name = "productName", value = "商品名称", required = false, dataType = "String", paramType = "query") 
    })
	@RequestMapping(value = "findProductByCategoryId",method=RequestMethod.GET)
	public Result<ProductCategoryVO> findProductByCategoryId(Long categoryId) {
    	List<ProductCategoryVO>  productCategoryVOs = productService.findProductByCategoryId(categoryId);
    	return ResultUtils.createDefResult(productCategoryVOs);
	}
    
    @ApiOperation(value = "查询商品（新品）")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "isNew", value = "是否是新品", required = false, dataType = "int", paramType = "query"),
			@ApiImplicitParam(name = "productName", value = "商品名称", required = false, dataType = "String", paramType = "query") 
	})
   	@RequestMapping(value = "findProduct",method=RequestMethod.GET)
   	public Result<ProductVO> findProduct(Integer isNew,String productName) {
       	List<ProductVO>  products = productService.findProduct(isNew,productName);
       	return ResultUtils.createDefResult(products);
   	}
    
    @ApiOperation(value = "获取商品详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "productId", value = "商品id", required = false, dataType = "long", paramType = "query") 
	})
   	@RequestMapping(value = "getProduct",method=RequestMethod.GET)
   	public Result<ProductVO> getProduct(Long productId) {
    	ProductVO  product = productService.getProduct(productId);
       	return ResultUtils.createDefResult(product);
   	}
	
    
    @ApiOperation(value = "根据规格值id查询赠送商品详情（弹出框）")
    @ApiImplicitParams({
		@ApiImplicitParam(name = "specificationValueId", value = "规格id", required = false, dataType = "String", paramType = "query") 
    })
	@RequestMapping(value = "getProductCategoryInfoByValueId",method=RequestMethod.GET)
	public Result<ProductCategoryVO> getProductSpecificationInfoByValueId(Long specificationValueId) {
    	if(specificationValueId == null){	
	        throw new ParamException("规格值id不能为空");
	    }
    	List<ProductSpecificationVO>  ProductSpecificationVOs = productSpecificationService.getProductSpecificationInfoByValueId(specificationValueId);
    	return ResultUtils.createDefResult(ProductSpecificationVOs);
	}

}